package com.ruoyi.mall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.MallEmployee;
import com.ruoyi.mall.service.IMallEmployeeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工管理Controller
 * 
 * @author banana_slices
 * @date 2024-12-01
 */
@RestController
@RequestMapping("/mall/employee")
public class MallEmployeeController extends BaseController
{
    @Autowired
    private IMallEmployeeService mallEmployeeService;

    /**
     * 查询员工管理列表
     */
    @PreAuthorize("@ss.hasPermi('mall:employee:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallEmployee mallEmployee)
    {
        startPage();

        if (getUserId() != 1)
        {
            //若userId不为1则添加查询限制
            mallEmployee.setCreateBy(getUsername());
        }
        List<MallEmployee> list = mallEmployeeService.selectMallEmployeeList(mallEmployee);
        return getDataTable(list);
    }

    /**
     * 导出员工管理列表
     */
    @PreAuthorize("@ss.hasPermi('mall:employee:export')")
    @Log(title = "员工管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallEmployee mallEmployee)
    {
        List<MallEmployee> list = mallEmployeeService.selectMallEmployeeList(mallEmployee);
        ExcelUtil<MallEmployee> util = new ExcelUtil<MallEmployee>(MallEmployee.class);
        util.exportExcel(response, list, "员工管理数据");
    }

    /**
     * 获取员工管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:employee:query')")
    @GetMapping(value = "/{employeeId}")
    public AjaxResult getInfo(@PathVariable("employeeId") Long employeeId)
    {
        return success(mallEmployeeService.selectMallEmployeeByEmployeeId(employeeId));
    }

    /**
     * 新增员工管理
     */
    @PreAuthorize("@ss.hasPermi('mall:employee:add')")
    @Log(title = "员工管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallEmployee mallEmployee)
    {
        mallEmployee.setCreateBy(getUsername());
        return toAjax(mallEmployeeService.insertMallEmployee(mallEmployee));
    }

    /**
     * 修改员工管理
     */
    @PreAuthorize("@ss.hasPermi('mall:employee:edit')")
    @Log(title = "员工管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallEmployee mallEmployee)
    {
        return toAjax(mallEmployeeService.updateMallEmployee(mallEmployee));
    }

    /**
     * 删除员工管理
     */
    @PreAuthorize("@ss.hasPermi('mall:employee:remove')")
    @Log(title = "员工管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{employeeIds}")
    public AjaxResult remove(@PathVariable Long[] employeeIds)
    {
        return toAjax(mallEmployeeService.deleteMallEmployeeByEmployeeIds(employeeIds));
    }
}
